const Jimp = require('jimp');

const imagePath = '1.jpeg';
const watermarkImagePath = '2023111414314633.jpeg'; // 替换为你的水印图片路径
const outputImagePath = '3.jpg';

const watermarkWidth = 200;
const watermarkHeight = 80;

Jimp.read(imagePath)
    .then(image => {
        return Jimp.read(watermarkImagePath)
            .then(watermarkImage => {
                const imageWidth = image.bitmap.width;
                const imageHeight = image.bitmap.height;

                // 计算水印的位置（右下角）
                const watermarkX = imageWidth - watermarkWidth;
                const watermarkY = imageHeight - watermarkHeight;

                // 将水印图片合成到原图上
                image.composite(watermarkImage, watermarkX, watermarkY);

                // 保存处理后的图片
                return image.write(outputImagePath);
            });
    })
    .catch(err => {
        console.error(err);
    });
